
package com.dps.omc.service.impl;
import com.dps.omc.enumer.EnumGroupType;
import com.dps.common.utils.IdGenerator;
import com.dps.omc.dao.IAgentNodeDAO;
import com.dps.omc.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dps.common.service.impl.AbstractPageService;
import com.dps.omc.service.IAgentNodeService;

import java.util.List;

@SuppressWarnings("unchecked")
@Service("AgentNodeServiceImpl")

public class AgentNodeServiceImpl extends AbstractPageService<IAgentNodeDAO,AgentNode> implements IAgentNodeService {

	@Autowired
	private IAgentNodeDAO agentNodeDAO;
	@Override
	public boolean getEnableDataPerm() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public IAgentNodeDAO getDao() {
		return agentNodeDAO;
	}

	@Override
	public void create(Agent agent, String nodeId, String bizType, EnumGroupType groupType) {
		this.deleteByProperty("nodeId",nodeId);
		AgentNode agentNode = new AgentNode();

		agentNode.setId(IdGenerator.createNewId());
		agentNode.setAgentId(agent.getId());
		agentNode.setNodeId(nodeId);
		agentNode.setGroupType(groupType);
		agentNode.setBizType(bizType);
		agentNode.setBizUnit(agent.getBizUnitName());

		this.insert(agentNode);
	}

	@Override
	public void createByDbServer(Agent agent, DbServer dbServer) {
		this.deleteByProperty("nodeId",dbServer.getId());
		AgentNode agentNode = new AgentNode();

		agentNode.setId(IdGenerator.createNewId());
		agentNode.setAgentId(agent.getId());
		agentNode.setNodeId(dbServer.getId());
		agentNode.setIp(dbServer.getDbHost());
		agentNode.setAlias(dbServer.getAlias());
		agentNode.setGroupType(dbServer.getGroupType());
		agentNode.setBizType(dbServer.getBizTypeName());
		agentNode.setBizUnit(agent.getBizUnitName());
		agentNode.setSysRank(dbServer.getSysRank());
		agentNode.setOpSystem(dbServer.getOpSystem());
		agentNode.setTeam(dbServer.getTeam());

		this.insert(agentNode);
	}

	@Override
	public void createByServer(Agent agent, Server server) {
		this.deleteByProperty("nodeId",server.getId());
		AgentNode agentNode = new AgentNode();

		agentNode.setId(IdGenerator.createNewId());
		agentNode.setAgentId(agent.getId());
		agentNode.setNodeId(server.getId());
		agentNode.setIp(server.getHost());
		agentNode.setAlias(server.getAlias());
		agentNode.setGroupType(server.getGroupType());
		agentNode.setBizType(server.getBizTypeName());
		agentNode.setBizUnit(agent.getBizUnitName());
		agentNode.setSysRank(server.getSysRank());
		agentNode.setOpSystem(server.getOpSystem());
		agentNode.setTeam(server.getTeam());
		this.insert(agentNode);
	}

	@Override
	public void createByTelnetServer(Agent agent, TelnetServer telnetServer) {
		this.deleteByProperty("nodeId",telnetServer.getId());
		AgentNode agentNode = new AgentNode();

		agentNode.setId(IdGenerator.createNewId());
		agentNode.setAgentId(agent.getId());
		agentNode.setNodeId(telnetServer.getId());
		agentNode.setIp(telnetServer.getHost());
		agentNode.setAlias(telnetServer.getAlias());
		agentNode.setGroupType(telnetServer.getGroupType());
		agentNode.setBizType(telnetServer.getBizTypeName());
		agentNode.setBizUnit(agent.getBizUnitName());
		agentNode.setSysRank(telnetServer.getSysRank());
		agentNode.setOpSystem(telnetServer.getOpSystem());
		agentNode.setTeam(telnetServer.getTeam());
		this.insert(agentNode);
	}

	@Override
	public List<AgentNode> findListByAgent(String agentId, List<String> bizTypes, EnumGroupType groupType) {
		return getDao().findListByAgent(agentId, bizTypes, groupType);
	}
}
